package com.joinway.framework.admin.core.service;

import java.util.List;

import org.apache.commons.collections.CollectionUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import com.joinway.framework.admin.bean.domain.UserProfile;
import com.joinway.framework.bean.logging.annotation.InputLog;
import com.joinway.framework.core.plugin.PluginAdaptor;
import com.joinway.framework.data.jdbc.repository.TableRepository;
import com.joinway.framework.extension.utils.DataUtils;

@Service
class UserProfileService extends PluginAdaptor implements IUserProfileService {

	@Autowired protected TableRepository repository;
	
	@Transactional(propagation=Propagation.NOT_SUPPORTED,readOnly=true)
	@InputLog
	@Override
	public UserProfile getUserProfile(String id) throws Exception {
		int userId = DataUtils.convertToInt(id);
		
		List<UserProfile> profiles = repository.find(UserProfile.class, "select * from user_profile where user_id = ?", userId);
		
		return CollectionUtils.isNotEmpty(profiles) ? profiles.get(0) : null;
	}


}
